//
//  SLMineViewModel.m
//  StarLight
//
//  Created by Duke.wu on 16/5/12.
//  Copyright © 2016年 Duke.Wu. All rights reserved.
//

#import "SLMineViewModel.h"
#import "SLNetWork.h"





@implementation SLMineViewModel


+ (instancetype)shareInstance{
  static SLMineViewModel *model;
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
    model = [[SLMineViewModel alloc] init];
  });
  return model;
}


- (instancetype)init{
  self = [super init];
  if (self) {
    [self getUserindex];
    [self getUserindexCallBack:^(id respond, NSError *error) {
    }];
  }
  return self;
}

- (void)getUserindex{
  NSDictionary *userData = [DEFAULTS objectForKey:@"userData"];
  if (userData != nil) {
      self.indexModel = [SLMineUserIndexModel mj_objectWithKeyValues:userData];
  }
}


- (void)getUserindexCallBack:(UserIndexComplete)block{
  
  NSDictionary *dic = [DEFAULTS objectForKey:@"loginInformation"];
  NSString *url = [NSString stringWithFormat:@"%@/%@/%@?uid=%@",baseUrl,@"user",@"userindex",dic[@"id"]];
  
  @weakify(self)
  [SLNetWork getDataWithRequest:url complete:^(id respond, NSError *error) {
    if (!error) {
      @strongify(self)
      SLMineUserIndexModel *model = [SLMineUserIndexModel mj_objectWithKeyValues:respond[@"data"]];
      self.indexModel = model;
      [DEFAULTS setObject:respond[@"data"] forKey:@"userData"];
      [DEFAULTS setObject:@(model.type) forKey:@"userType"];
      [DEFAULTS synchronize];
    }
    block(respond,error);
  }];
}
@end

@implementation SLMineUserIndexModel

+ (NSDictionary *)mj_objectClassInArray{
    return @{@"banner" : [Banner class]};
}


@end

@implementation Banner



@end

